import time

import requests

# 1.登录
url = "http://mall.lemonban.com:8107/login"
req_data = {"principal": "17762450607", "credentials": "5201314zjx", "appType": 3, "loginType": 0}
resp = requests.request("post", url, json=req_data)
token = resp.json()["access_token"]
print(token)
print("登录响应状态码：", resp.status_code)

# 2.创建订单
url = "http://mall.lemonban.com:8107/p/order/confirm"
req_data = {"addrId": 0, "orderItem": {"prodId": 148, "skuId": 491, "prodCount": 1, "shopId": 1}, "couponIds": [],"isScorePay": 0, "userChangeCoupon": 0, "userUseScore": 0}
headers = {"Authorization": f"bearer{token}"}
resp = requests.request("post", url, json=req_data, headers=headers)
print(resp.status_code)
print(resp.text)

# 3.提交订单
url = "http://mall.lemonban.com:8107/p/order/submit"
req_data = {"orderShopParam": [{"remarks": "", "shopId": 1}]}
resp = requests.request("post", url, json=req_data, headers=headers)
print(resp.text)  # {"orderNumbers":"1503578516212682752","duplicateError":null}
order_number = resp.json()["orderNumbers"]
# 4.支付
url = "http://mall.lemonban.com:8107/p/order/pay"
req_data = {"payType": 3, "orderNumbers": f"{order_number}"}
resp = requests.request("post", url, json=req_data, headers=headers)
print(resp.text)  # weixin://wxpay/bizpayurl?pr=dxpD05Izz

# 5、模拟支付返回
url = 'http://mall.lemonban.com:8107/notice/pay/3'
data = {
    "payNo": order_number,  # 商城支付订单号
    "bizPayNo": str(int(time.time() * 1000)),  # 微信方的订单号
    "isPaySuccess": True,  # True 成功，False 失败
}
resp = requests.request("post", url, json=data, headers=headers)
print(resp.text)
